package cn.ruituo.adv8.server;

import java.io.*;
import java.net.Socket;

public class FileThread2 extends Thread {
    private Socket s;
    public FileThread2(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        //你告诉我名字，把这个名字的文件发给你
        System.out.println(s+"连接成功！");
        //发文件给你
        File file=new File("D:\\Documents\\图片和资料");
        try {
            OutputStream out=s.getOutputStream();
            InputStream in=s.getInputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            String name=br.readLine();
            FileInputStream fin=new FileInputStream(new File(file,name));
            byte b[]=new byte[fin.available()];
            fin.read(b);
            fin.close();
            out.write(b);
            System.out.println("图片"+name+"发送给"+s+"成功");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
